<?php
/**
 * User: htt
 * Date: 2019-02-20
 * Time: 上午10:54
 */

namespace App\Models\User;

use App\Models\Admin\OrderBaleModel;
use App\Models\CompanysModel;
use App\Models\Model;
/**
This is the model class for table "users_orders".
 * @property int10unsigned id	订单id
 * @property varchar33 order_no	订单号
 * @property mediumint8unsigned bale	货单ID，对接orders_bales
 * @property int10unsigned temp	抢单ID，对接orders_temp
 * @property int10unsigned cid	公司UID
 * @property int10unsigned fid	工厂UID
 * @property mediumint8unsigned num	加工数量，件
 * @property decimal92 money
 * @property decimal92unsigned bond_money	保证金
 * @property varchar20 kd_name	快递名
 * @property varchar30 kd_code	快递单号
 * @property int11 kd_time	发货时间
 * @property varchar255 note	厂家备注
 * @property tinyint3unsigned status	订单状态：1未发原料，2接收原料，3生产中，4客户跟单，5确认跟单，6打包发货，7到货签收，8评价，9已完成
 * @property text other	其他自定义字段
 * @property int10unsigned created_at	订单生成时间
 * @property int10unsigned updated_at	更新
 * @property mediumtext yuanliao	原料 以json形式保存
 * @property int10unsigned yuanliao_time	0表示还没发送给工厂,非0表示发送时间,也就是发送给工厂
 * @property varchar255 receiving_address	收件地址
 * @property varchar255 send_address	发货地址
 */
class UserOrdersModel extends Model
{
    protected $table = 'users_orders';

    
    
    const status_weifayuanliao=1;
    const status_jieshouyuanliao=2;
    const status_shengchanzhong=3;
    
    const status_kehugendan=4;    
    const status_querengendan=5;    
    const status_dabaofahuo=6;
    
    const status_daohuoqianshou=7;    
    const status_pingjia=8;
    const status_wancheng=9;

    const complete_no=0;
    const complete_yes=1;


        public static function getStatus($status=null){
        $list=[
            self::status_weifayuanliao=>'未发原料',
            self::status_jieshouyuanliao=>'接收原料',
            self::status_shengchanzhong=>'生产中',
            
            self::status_kehugendan=>'客户跟单',
            self::status_querengendan=>'确认跟单',
            self::status_dabaofahuo=>'打包发货',
            
            self::status_daohuoqianshou=>'到货签收',
            self::status_pingjia=>'评价',
            self::status_wancheng=>'完成',

        ];
        if(!$status){
            return $list;
        }
        return isset($list[$status])?$list[$status]:'';
    }
    
    
    
    
    public function orderDetail()
    {
        return $this->hasOne(OrderBaleModel::class, 'id', 'bale');
    }
    
    public function orderCompany(){
        return $this->hasOne(CompanysModel::class, 'uid', 'cid');
    }

    public function orderFactory()
    {
        return $this->hasOne(CompanysModel::class, 'uid', 'fid');
    }





    public function attributeLabels() {
        return [
            'id' => '订单id',
            'order_no' => '订单号',
            'bale' => '货单ID',
            'temp' => '抢单ID',
            'cid' => '公司UID',
            'fid' => '工厂UID',
            'num' => '加工数量，件',
            'money' => '',
            'bond_money' => '保证金',
            'kd_name' => '快递名',
            'kd_code' => '快递单号',
            'kd_time' => '发货时间',
            'note' => '厂家备注',
            'status' => '状态',
            'other' => '其他自定义字段',
            'created_at' => '订单生成时间',
            'updated_at' => '更新',
            'yuanliao' => '原料 以json形式保存',
            'yuanliao_time' => '0表示还没发送给工厂,非0表示发送时间,也就是发送给工厂',
            'receiving_address' => '收件地址',
            'send_address' => '发货地址',
        ];
    }







}
